package com.fieldchain.ex.fa100.custom.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;

/**
 * Created by 123 on 2018/6/8.
 */

public class ProgressDialog extends BaseDialog {
    private ImageView progressView;
    private TextView progressMessage;
    private AnimationDrawable animationDrawable = null;

    public ProgressDialog(Context context) {
        super(context);
    }

    @Override
    public int setLayout() {
        return R.layout.dialog_progress;
    }

    @Override
    public void findView() {
        progressView = (ImageView) findViewById(R.id.progress_view);
        progressMessage = (TextView) findViewById(R.id.progress_message);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.dimAmount = 0f;
        getWindow().setAttributes(lp);
    }

    public void setContent(String content) {
       if(content!=null){
           progressMessage.setText(content);
       }
    }

    @Override
    public void setValue() {
        progressView.setImageResource(R.drawable.progress_dialog);
        animationDrawable = (AnimationDrawable) progressView.getDrawable();
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                animationDrawable.stop();
            }
        });
    }

    @Override
    public void show() {
        super.show();
        if (animationDrawable != null) {
            animationDrawable.setOneShot(false);
            animationDrawable.start();
        }
    }

}
